package IO;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class byteStream {
    public static void main(String[] args) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream(12);

        while (out.size() != 30) {      //控制输入的字符数，这个size不是上面构造方法的size
            // 获取用户输入值
            out.write(System.in.read());
        }

        byte b[] = out.toByteArray();
        System.out.println("Print the content");

        /*for(int x= 0 ; x < b.length; x++) {
            // 打印字符
            System.out.print((char)b[x]  + "   ");  //转换为char类型，但不能打印中文
        }
        System.out.println("   ");*/

        System.out.println(out.toString());


        ByteArrayInputStream in = new ByteArrayInputStream(b);

        System.out.println("Converting characters to Upper case ");
        int count = 0;
        byte[] bytes = new byte[1024];

        while ((count = in.read(bytes)) != -1) {
            System.out.println(new String(bytes, 0, count));
        }
        in.reset();

    }
}
